package com.xnyzc.lhy.order.controller.capi.user.pay;

import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.common.util.TokenUtil;
import com.xnyzc.lhy.order.entity.param.user.pay.UserRechargeParam;
import com.xnyzc.lhy.order.service.user.pay.IOaCUserRechargeService;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * @Description 用户充值
 * @Author zhuyubin
 * @Date 2019/8/14 14:25
 **/
@RestController
@RequestMapping(value = "capi/oaCUserRecharge")
public class OaCUserRechargeController {

    @Autowired
    private IOaCUserRechargeService iOaCUserRechargeService;

    /**
     *
     * @param userRechargeParam
     * @return
     */
    @PostMapping(value = "userRecharge")
    public Rv userRecharge(@ApiParam(name = "userRechargeParam", value = "入参实体") @RequestBody UserRechargeParam userRechargeParam){
        Long userId = TokenUtil.getTokenUserId();
        if (CheckUtil.objIsEmpty(userId)){
            throw PangException.create(EErrorCode.tokenExpire);
        }
        String tag = TokenUtil.getTag();
        if (CheckUtil.objIsEmpty(tag)){
            throw PangException.create(EErrorCode.missingAuthArgs);
        }
        Integer type = userRechargeParam.getType();
        BigDecimal money = userRechargeParam.getMoney();
        if (CheckUtil.objIsEmpty(type, money)){
            throw PangException.create(EErrorCode.missingArg);
        }
        return Rv.wrap(iOaCUserRechargeService.userRecharge(userId, tag, type, money));
    }
}
